import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:saas_order_meal/model/week_food_model.dart';

import '../model/order_request_data.dart';

class WeekMenuChooseViewModel extends BaseViewModel {
  final OrderRequestData orderData;
  WeekMenuChooseViewModel(BuildContext? context,
      {required this.orderData,})
      : super(context);

  var weekMenuModel = WeekFoodModel();
  Map<String, dynamic>? menuData;

  @override
  void onCreated() {
    super.onCreated();
    getWeekMenu();
  }

  Future<void> getWeekMenu() async {
    showLoadingState();
    try {
      menuData = await weekMenuModel.getWeekMenuByDay(
          siteId: orderData.siteId,
          date: orderData.date??"",
          elderHumanId: orderData.elderHumanId,
          timeSection: orderData.timeSection);
      orderData.menuId = menuData!["menuId"];
      orderData.menuTypeId = menuData!["menuTypeId"];
      print("666666====>${ orderData.menuTypeId}");
      var menuList = menuData!['menuList'] as List;
      if (menuList.isEmpty) {
        showEmptyState(msg: "无菜单数据");
      } else {
        showContent();
        notifyListeners();
      }
    } catch (e) {
      showErrorState( e.toNetError());
    }
  }
}
